package com.xxhui.slidingmenudemo;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.xxhui.slidingmenudemo.Adapter.MenuAdapter;
import com.xxhui.slidingmenudemo.View.SlidingMenu;

public class MainActivity extends AppCompatActivity {

    private SlidingMenu slideMenu1;
    private ListView lv_menu;
    private MenuAdapter menuAdapter;
    private ImageView iv_menu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //ActionBar actionBar = getSupportActionBar();
        //actionBar.hide();
        //setSupportActionBar(null);
        setContentView(R.layout.activity_main);

        showInStatusBar2();
        initView();
    }

    private void initView() {
        slideMenu1 = (SlidingMenu) findViewById(R.id.slidingmenu);
        lv_menu = (ListView) findViewById(R.id.menu_lv);
        iv_menu = (ImageView) findViewById(R.id.main_top_iv);
        menuAdapter = new MenuAdapter(this);
        lv_menu.setAdapter(menuAdapter);
        iv_menu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                slideMenu1.toggle();
            }
        });
        slideMenu1.setOnStatusListener(new SlidingMenu.OnStatusListener() {

            @Override
            public void statusChanged(SlidingMenu.Status status) {
                if (status == SlidingMenu.Status.Open) {
                    Toast.makeText(MainActivity.this, "Open", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "Close", Toast.LENGTH_SHORT).show();
                }

            }
        });
    }

    public void showInStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
    }
//一样的效果
    public void showInStatusBar2(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
    }
}
